﻿using System.Collections.ObjectModel;
using System.Windows;
using DesktopToyWpf.Convertors;

namespace DesktopToyWpf.ViewModels;

public class MainViewModel : ViewModelBase
{
    private DateTime NowCache;
    private WeatherImageType WeatherImageCache;
    private string WeatherCache = string.Empty;
    private float TemperatureCache;
    private string WindDirectionCache = string.Empty;
    private string WindPowerCache = string.Empty;
    private float HumidityCache;
    private string WeatherTipsCache;
    private float CpuTemperatureCache;
    private float GpuTemperatureCache;
    private float StorageTemperatureCache;
    private bool IsDayCache;
    private string SolarCalendarCache = string.Empty;
    private string LunarCalendarCache = string.Empty;
    private int HourPartCache;
    private int MinutePartCache;
    private int SecondPartCache;
    private int HappyCountCache;
    private string WeekPartCache;

    public DateTime Now
    {
        set
        {
            SetValue(ref NowCache, value);
            IsDay = value.Hour is >= 6 and <= 18;
            SolarCalendar = $"{value.Year} / {value.Month:00} / {value.Day:00}";
            LunarCalendar = DesktopToy.Core.Common.Utils.GetLunarDate(value);
            HourPart = value.Hour;
            MinutePart = value.Minute;
            SecondPart = value.Second;
            WeekPart = value.DayOfWeek switch
            {
                DayOfWeek.Monday => "星期一",
                DayOfWeek.Tuesday => "星期二",
                DayOfWeek.Wednesday => "星期三",
                DayOfWeek.Thursday => "星期四",
                DayOfWeek.Friday => "星期五",
                DayOfWeek.Saturday => "星期六",
                _ => "星期日"
            };
        }
        get => NowCache;
    }

    /// <summary>
    /// 阳历
    /// </summary>
    public string SolarCalendar
    {
        private set => SetValue(ref SolarCalendarCache, value); // 通过 Now 设置
        get => SolarCalendarCache;
    }

    /// <summary>
    /// 阴历
    /// </summary>
    public string LunarCalendar
    {
        private set => SetValue(ref LunarCalendarCache, value); // 通过 Now 设置
        get => LunarCalendarCache;
    }

    public int HourPart
    {
        private set => SetValue(ref HourPartCache, value); // 通过 Now 设置
        get => HourPartCache;
    }

    public int MinutePart
    {
        private set => SetValue(ref MinutePartCache, value); // 通过 Now 设置
        get => MinutePartCache;
    }

    public int SecondPart
    {
        private set => SetValue(ref SecondPartCache, value); // 通过 Now 设置
        get => SecondPartCache;
    }

    public string WeekPart
    {
        private set => SetValue(ref WeekPartCache, value); // 通过 Now 设置
        get => WeekPartCache;
    }

    /// <summary>
    /// 是否为白天
    /// </summary>
    public bool IsDay
    {
        private set // 通过 Now 设置
        {
            if (SetValue(ref IsDayCache, value))
            {
                WeatherImage = WeatherImage with { IsDay = value };
            }
        }
        get => IsDayCache;
    }

    /// <summary>
    /// 天气图标
    /// </summary>
    public WeatherImageType WeatherImage
    {
        private set => SetValue(ref WeatherImageCache, value); // 通过 Now 设置
        get => WeatherImageCache;
    }

    public string Weather
    {
        set
        {
            if (SetValue(ref WeatherCache, value))
            {
                WeatherImage = WeatherImage with { Name = value };
            }
        }
        get => WeatherCache;
    }

    public float Temperature
    {
        set => SetValue(ref TemperatureCache, value);
        get => TemperatureCache;
    }

    public string WindDirection
    {
        set
        {
            if (SetValue(ref WindDirectionCache, value))
            {
                OnPropertyChanged(nameof(WindInfo));
            }
        }
        get => WindDirectionCache;
    }

    public string WindPower
    {
        set
        {
            if (SetValue(ref WindPowerCache, value))
            {
                OnPropertyChanged(nameof(WindInfo));
            }
        }
        get => WindPowerCache;
    }

    /// <summary>
    /// 风力信息，例如：北风: ≤3
    /// </summary>
    public string WindInfo => $"{WindDirection}风：{WindPower}级";

    public float Humidity
    {
        set
        {
            if (SetValue(ref HumidityCache, value))
            {
                OnPropertyChanged(nameof(HumidityInfo));
            }
        }
        get => HumidityCache;
    }

    public string HumidityInfo => $"湿度：{(int)Humidity}%";

    public string WeatherTips
    {
        set => SetValue(ref WeatherTipsCache, value);
        get => WeatherTipsCache;
    }

    public float CpuTemperature
    {
        set => SetValue(ref CpuTemperatureCache, value);
        get => CpuTemperatureCache;
    }

    public float GpuTemperature
    {
        set => SetValue(ref GpuTemperatureCache, value);
        get => GpuTemperatureCache;
    }

    public float StorageTemperature
    {
        set => SetValue(ref StorageTemperatureCache, value);
        get => StorageTemperatureCache;
    }

    /// <summary>
    /// 心情坐标点。X取值[0,24]，Y取值[0,4]，取值可以是小数
    /// </summary>
    public ObservableCollection<Point> MoodPoints { set; get; } = [];


    public int HappyCount
    {
        set => SetValue(ref HappyCountCache, value);
        get => HappyCountCache;
    }
}